package com.alibaba.sample.kantiezi.biz.store.ao;

import com.alibaba.biz.command.ao.ApplicationObjectSupport;
import com.alibaba.biz.command.result.Result;
import com.alibaba.biz.command.result.ResultSupport;

import com.alibaba.sample.kantiezi.dal.dao.CategoryDao;
import com.alibaba.sample.kantiezi.dal.dao.ProductDao;
import com.alibaba.sample.kantiezi.dal.dataobject.Category;
import com.alibaba.sample.kantiezi.dal.dataobject.Product;
import com.alibaba.sample.kantiezi.biz.store.manager.StoreManager;

import java.util.List;

public class ItemList extends ApplicationObjectSupport {
    private StoreManager storeManager;
    private ProductDao   productDao;
    private CategoryDao  categoryDao;
    private String       productId;

    public void setStoreManager(StoreManager storeManager) {
        this.storeManager = storeManager;
    }

    public void setProductDao(ProductDao productDao) {
        this.productDao = productDao;
    }

    public void setCategoryDao(CategoryDao categoryDao) {
        this.categoryDao = categoryDao;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public Result execute() {
        List     items    = storeManager.getAllItems(productId);
        Product  product  = productDao.getProductById(productId);
        Category category = categoryDao.getCategoryById(product.getCategoryId());
        Result   result   = new ResultSupport();

        result.getModels().put("category", category);
        result.getModels().put("product", product);
        result.setDefaultModel(items);

        return result;
    }
}
